package com.leyou.common;

import com.fasterxml.jackson.core.type.TypeReference;
import com.leyou.common.utils.JsonUtils;
import lombok.Data;

import java.awt.print.Printable;
import java.util.List;
import java.util.Map;

public class MyChange {
    
    static String json1 = "[{\"group\":\"主体\",\"params\":[{\"k\":\"品牌\",\"searchable\":false,\"global\":true," +
            "\"options\":[]}," +
            "{\"k\":\"型号\",\"searchable\":false,\"global\":true,\"options\":[]},{\"k\":\"上市年份\",\"searchable\":false," +
            "\"global\":true,\"options\":[],\"numerical\":true,\"unit\":\"年\"}]},{\"group\":\"基本信息\"," +
            "\"params\":[{\"k\":\"机身颜色\",\"searchable\":false,\"global\":false,\"options\":[]},{\"k\":\"机身重量（g）\",\"searchable\":false,\"global\":true,\"options\":[],\"numerical\":true,\"unit\":\"g\"},{\"k\":\"机身材质工艺\",\"searchable\":false,\"global\":true,\"options\":[]}]},{\"group\":\"操作系统\",\"params\":[{\"k\":\"操作系统\",\"searchable\":true,\"global\":true,\"options\":[\"安卓\",\"IOS\",\"Windows\",\"功能机\"]}]},{\"group\":\"主芯片\",\"params\":[{\"k\":\"CPU品牌\",\"searchable\":true,\"global\":true,\"options\":[\"骁龙（Snapdragon)\",\"麒麟\"]},{\"k\":\"CPU型号\",\"searchable\":false,\"global\":true,\"options\":[]},{\"k\":\"CPU核数\",\"searchable\":true,\"global\":true,\"options\":[\"一核\",\"二核\",\"四核\",\"六核\",\"八核\",\"十核\"]},{\"k\":\"CPU频率\",\"searchable\":true,\"global\":true,\"options\":[],\"numerical\":true,\"unit\":\"GHz\"}]},{\"group\":\"存储\",\"params\":[{\"k\":\"内存\",\"searchable\":true,\"global\":false,\"options\":[\"1GB及以下\",\"2GB\",\"3GB\",\"4GB\",\"6GB\",\"8GB\"],\"numerical\":false,\"unit\":\"\"},{\"k\":\"机身存储\",\"searchable\":true,\"global\":false,\"options\":[\"8GB及以下\",\"16GB\",\"32GB\",\"64GB\",\"128GB\",\"256GB\"],\"numerical\":false,\"unit\":\"\"}]},{\"group\":\"屏幕\",\"params\":[{\"k\":\"主屏幕尺寸（英寸）\",\"searchable\":true,\"global\":true,\"options\":[],\"numerical\":true,\"unit\":\"英寸\"},{\"k\":\"分辨率\",\"searchable\":false,\"global\":true,\"options\":[]}]},{\"group\":\"摄像头\",\"params\":[{\"k\":\"前置摄像头\",\"searchable\":true,\"global\":true,\"options\":[],\"numerical\":true,\"unit\":\"万\"},{\"k\":\"后置摄像头\",\"searchable\":true,\"global\":true,\"options\":[],\"numerical\":true,\"unit\":\"万\"}]},{\"group\":\"电池信息\",\"params\":[{\"k\":\"电池容量（mAh）\",\"searchable\":true,\"global\":true,\"options\":[],\"numerical\":true,\"unit\":\"mAh\"}]}]";
    
    
    static String json2 = "[{\"group\":\"主体\",\"params\":[{\"k\":\"品牌\",\"searchable\":false,\"global\":true," +
            "\"numerical\":false,\"unit\":\"\",\"options\":[]},{\"k\":\"适用机型\",\"searchable\":false,\"global\":false,\"numerical\":false,\"unit\":\"\",\"options\":[]}]},{\"group\":\"规格尺寸\",\"params\":[{\"k\":\"贴膜尺寸\",\"searchable\":true,\"global\":true,\"numerical\":true,\"unit\":\"英寸\",\"options\":[]},{\"k\":\"材质\",\"searchable\":true,\"global\":true,\"numerical\":false,\"unit\":\"\",\"options\":[\"钢化玻璃\",\"水凝膜\"]},{\"k\":\"类型\",\"searchable\":true,\"global\":true,\"numerical\":false,\"unit\":\"\",\"options\":[\"前膜\",\"后膜\",\"磨砂\",\"防指纹\",\"高透膜\"]}]}]";
    
    
    static String json3 = "[{\"group\":\"主体参数\",\"params\":[{\"k\":\"品牌\",\"searchable\":false,\"global\":true," +
            "\"numerical\":false,\"unit\":\"\",\"options\":[]},{\"k\":\"型号\",\"searchable\":false,\"global\":false,\"numerical\":false,\"unit\":\"\",\"options\":[]},{\"k\":\"产品颜色\",\"searchable\":false,\"global\":true,\"numerical\":false,\"unit\":\"\",\"options\":[]},{\"k\":\"上市日期\",\"searchable\":false,\"global\":true,\"numerical\":false,\"unit\":\"\",\"options\":[]},{\"k\":\"能效等级\",\"searchable\":true,\"global\":true,\"numerical\":false,\"unit\":\"\",\"options\":[\"一级能效\",\"二级能效\",\"三级能效\",\"政府节能\"]}]},{\"group\":\"显示参数\",\"params\":[{\"k\":\"屏幕尺寸\",\"searchable\":true,\"global\":false,\"numerical\":true,\"unit\":\"英寸\",\"options\":[]},{\"k\":\"屏幕分辨率\",\"searchable\":true,\"global\":true,\"numerical\":false,\"unit\":\"\",\"options\":[\"超高清\",\"全高清\",\"高清\"]}]}]";
    
    public static void main(String[] args) {
    
    
        // tempClasses.forEach(System::out);
        // int i = 11;
        // for (final TempClass tempClass : JsonUtils.nativeRead(json3, new TypeReference<List<TempClass>>() {
        // })) {
        //     String insert =
        //             "INSERT INTO `leyou`.`tb_spec_group`(`id`, `cid`, `name`) VALUES (null, 105, '" + tempClass.getGroup() +
        //                     "');";
        //     // System.out.println(insert);
        //
        //     for (TempParams tempParams : tempClass.getParams()) {
        //         String sql = "INSERT INTO `leyou`.`tb_spec_param`(`id`, `cid`, `group_id`, `name`, `numeric`, `unit`, " + "`generic`, `searching`, `segments`) VALUES (" +
        //                 "null, " + 105 + ", " + i + ", '" + tempParams.getK() + "', " + "b'" + (tempParams.numerical ?
        //                 '1' : '0') + "'" + ", '" + tempParams.getUnit() + "', b'" + (tempParams.global ? '1' : '0') + "', b'" + (tempParams.searchable ? '1' : '0') + "', '');";
        //         System.out.println(sql);
        //     }
        //     i++;
        // }
        
        
        String testJson = "[{\"group\":\"主体\",\"params\":[{\"k\":\"品牌\",\"searchable\":false,\"global\":true," +
                "\"v\":\"黑马\"},{\"k\":\"型号\",\"searchable\":false,\"global\":true,\"v\":\"黑马3号\"},{\"k\":\"上市年份\",\"searchable\":false,\"global\":true,\"numerical\":true,\"unit\":\"年\",\"v\":\"2019\"}]},{\"group\":\"基本信息\",\"params\":[{\"k\":\"机身颜色\",\"searchable\":false,\"global\":false},{\"k\":\"机身重量（g）\",\"searchable\":false,\"global\":true,\"numerical\":true,\"unit\":\"g\",\"v\":\"198\"},{\"k\":\"机身材质工艺\",\"searchable\":false,\"global\":true,\"v\":\"金属\"}]},{\"group\":\"操作系统\",\"params\":[{\"k\":\"操作系统\",\"searchable\":true,\"global\":true,\"v\":\"安卓\"}]},{\"group\":\"主芯片\",\"params\":[{\"k\":\"CPU品牌\",\"searchable\":true,\"global\":true,\"v\":\"骁龙（Snapdragon)\"},{\"k\":\"CPU型号\",\"searchable\":false,\"global\":true,\"v\":\"骁龙845\"},{\"k\":\"CPU核数\",\"searchable\":true,\"global\":true,\"v\":\"八核\"},{\"k\":\"CPU频率\",\"searchable\":true,\"global\":true,\"numerical\":true,\"unit\":\"GHz\",\"v\":\"2.6\"}]},{\"group\":\"存储\",\"params\":[{\"k\":\"内存\",\"searchable\":true,\"global\":false,\"numerical\":false,\"unit\":\"\"},{\"k\":\"机身存储\",\"searchable\":true,\"global\":false,\"numerical\":false,\"unit\":\"\"}]},{\"group\":\"屏幕\",\"params\":[{\"k\":\"主屏幕尺寸（英寸）\",\"searchable\":true,\"global\":true,\"numerical\":true,\"unit\":\"英寸\",\"v\":\"5.9\"},{\"k\":\"分辨率\",\"searchable\":false,\"global\":true,\"v\":\"2180*1280\"}]},{\"group\":\"摄像头\",\"params\":[{\"k\":\"前置摄像头\",\"searchable\":true,\"global\":true,\"numerical\":true,\"unit\":\"万\",\"v\":\"1200\"},{\"k\":\"后置摄像头\",\"searchable\":true,\"global\":true,\"numerical\":true,\"unit\":\"万\",\"v\":\"1800\"}]},{\"group\":\"电池信息\",\"params\":[{\"k\":\"电池容量（mAh）\",\"searchable\":true,\"global\":true,\"numerical\":true,\"unit\":\"mAh\",\"v\":\"4000\"}]}]";
        final List<TempClass> tempClassesList = JsonUtils.nativeRead(testJson, new TypeReference<List<TempClass>>() {
        });
        for (final TempClass tempClass : tempClassesList) {
            for (final TempParams param : tempClass.getParams()) {
                System.out.println(param.getV());
            }
        }
        
    }
}

@Data
class TempClass {
    String group;
    List<TempParams> params;
}

@Data
class TempParams {
    String k;
    boolean searchable;
    boolean global;
    boolean numerical;
    String[] options;
    String unit;
    String v;
    
}
